    program clean_util2
      character*120 raw
      character*6 ticker,util
      character*8 date,astid
      character*9 cusip
      character*13 value,units
 !     character*11 util
      dimension ic(7)
      open(unit=10,file='e:\FIS\H_U2_20140101_20140331_rep.txt')
      open(unit=98,file='e:\FIS\test.txt')
      open(unit=99,file='e:\FIS\util_201401_201403_rep.txt')
      i=0
1     i=i+1      
      read(10,1000,end=500)raw
!      write(6,1000)raw
1000  format(a120)
      n=0
      nc=0
3     n=n+1
      if(raw(n:n).ne.'|') go to 3
      nc=nc+1
      ic(nc)=n
      if(nc.lt.7) go to 3
      if(i.eq.1) go to 1
      it1=ic(3)+1
      it2=ic(3)+2
      if(raw(it1:it1).ne.'U') go to 1
      if(raw(it2:it2).ne.'S') go to 1
      astid='        '
      ticker='      '
      date='        '
      cusip='         '
      units='             '
      value='             '
      util='   .00'
      iend=ic(1)-1
      k=9
      do 5 ii=iend,1,-1
          k=k-1
5     astid(k:k)=raw(ii:ii)
      ii1=ic(1)+1
      ii4=ic(1)+4
      ii6=ic(1)+6
      ii7=ic(1)+7
      ii9=ic(1)+9
      ii10=ic(1)+10
      
      date(1:4)=raw(ii1:ii4)
      date(5:6)=raw(ii6:ii7)
      date(7:8)=raw(ii9:ii10)
      ibg=ic(2)+1
      iend=ic(2)+9
      k=0
      do 15 ii=ibg,iend
          k=k+1
15    cusip(k:k)=raw(ii:ii)
      ibg=ic(4)+1
      iend=ic(5)-1
      if(ibg.gt.iend) go to 22
      k=0
      do 20 ii=ibg,iend
          k=k+1
          if(k.gt.6) go to 20
          ticker(k:k)=raw(ii:ii)
20    continue
22    continue
      ibg=ic(5)+1
      iend=ic(6)-1
      id=0
      do 30 ii=ibg,iend
30    if(raw(ii:ii).eq.'.') id=ii
      if(id.eq.0) go to 32
      iend=id-1
32    k=4
      do 35 ii=iend,ibg,-1
          k=k-1
35    util(k:k)=raw(ii:ii)
      ibg=id+1
      iend=ic(6)-1
      if(ibg.gt.iend) go to 38
      k=4
      do 37 ii=ibg,iend
          k=k+1
          if(k.gt.6) go to 37
          util(k:k)=raw(ii:ii)
37    continue 
38    continue      
      ibg=ic(6)+1
      iend=ic(7)-1
      id=0
      do 40 ii=ibg,iend
40    if(raw(ii:ii).eq.'.') id=ii
      if(id.eq.0) go to 42
      iend=id-1
42    k=14
      do 45 ii=iend,ibg,-1
          k=k-1
45    units(k:k)=raw(ii:ii)
      id=0
      ibg=ic(7)+1
      ii=ibg-1
50    ii=ii+1
      if(raw(ii:ii).ne.'.'.and.raw(ii:ii).ne.' ') go to 50
      iend=ii-1
      k=14
      do 60 ii=iend,ibg,-1
      k=k-1
      value(k:k)=raw(ii:ii)
60    continue      
      
100   continue
!      write(6,9900)astid,date,cusip,ticker,contr,loanty,coll,tickets,units,value,age,lavg,lmax,lmin,lstd
!      write(99,9900)astid,date,cusip,ticker,contr,loanty,coll,tickets,units,value,age,lavg,lmax,lmin,lstd
!9900  format(1x,a8,1x,a8,1x,a9,1x,a6,3(1x,a1),1x,a6,1x,a14,1x,a14,5(1x,a11))      
      write(6,9900)astid,date,cusip,ticker,util,units,value
      write(99,9900)astid,date,cusip,ticker,util,units,value
9900  format(1x,a8,1x,a8,1x,a9,1x,a6,1x,a6,2(1x,a13))      
!      if(i.lt.10000) go to 1
      go to 1
500   continue      
      stop

    end program clean_util2
